package com.hnzq.cloud.sendassembly.service.impl;

import cn.hutool.core.lang.Snowflake;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hnzq.cloud.IO.AddSendOrderIO;
import com.hnzq.cloud.IO.EditSendOrderIO;
import com.hnzq.cloud.IO.entity.FreSend;
import com.hnzq.cloud.sendassembly.mapper.FreSendMapper;
import com.hnzq.cloud.sendassembly.service.FreSendService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnzq.cloud.util.ComUtil;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tiangle
 * @since 2022-02-07
 */
@Service
public class FreSendServiceImpl extends ServiceImpl<FreSendMapper, FreSend> implements FreSendService {

    @Override
    public FreSend getById(Long id) {
        QueryWrapper<FreSend> freSendQueryWrapper = new QueryWrapper<>();
        freSendQueryWrapper.eq("send_id",id);
        FreSend one = getOne(freSendQueryWrapper);
        return one;
    }

    @Override
    public AddSendOrderIO addSend(AddSendOrderIO addSendOrderIO) {
        FreSend freSend = ComUtil.copyProperties(addSendOrderIO, FreSend.class);
        freSend.setCreateTime(ComUtil.nowDateTime());
        freSend.setSendStatus(0);
        Snowflake snowflake = new Snowflake();
        Long longId = snowflake.nextId();
        freSend.setSendId(longId);
        boolean save = save(freSend);
        System.out.println("保存fresend的情况:"+save);
        System.out.println(freSend.toString());
        addSendOrderIO.setSendId(freSend.getSendId());
        addSendOrderIO.setSendStatus(0);
        return addSendOrderIO;
    }

    @Override
    public boolean editSend(EditSendOrderIO editSendOrderIO) {
        FreSend byId = getById(editSendOrderIO.getSendId());
        byId.setUpdateTime(ComUtil.nowDateTime());
        byId.setSendStatus(editSendOrderIO.getSendStatus());
        QueryWrapper<FreSend> freSendQueryWrapper = new QueryWrapper<>();
        freSendQueryWrapper.eq("send_id",byId.getSendId());
        return update(byId,freSendQueryWrapper);
    }
}
